package com.sayice.icemusic.sort.impl;

import com.sayice.icemusic.pojo.Music;
import com.sayice.icemusic.sort.MusicSort;

import java.util.List;

/**
 * 按歌手名排序
 *
 * @author shubing
 */
public class ArtistSort implements MusicSort {
    @Override
    public void sort(List<Music> musicList, String searchedName) {
        musicList.sort((m1, m2) -> {
            if (m1 == null) {
                if (m2 == null) {
                    return 0;
                }
                return 1;
            }
            if (m2 == null) {
                return -1;
            }
            String name1 = m1.getArtistName();
            String name2 = m2.getArtistName();
            if (name1 == null) {
                if (name2 == null) {
                    return 0;
                }
                return 1;
            }
            if (name2 == null) {
                return -1;
            }
            return name1.compareTo(name2);
        });
    }
}
